#include <iostream>
#include <algorithm>
using namespace std;
const int N = 5050;
typedef pair<int, int> PII;
PII tim[N];
int n;

int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> tim[i].first >> tim[i].second;
    sort(tim, tim + n);
    int max_t = tim[0].second - tim[0].first, max_wt = 0;
    int l = tim[0].first, r = tim[0].second;
    for (int i = 1; i < n; ++i)
    {
        if (tim[i].first <= r)
            r = max(r, tim[i].second);
        else // 中间有间隔
        {
            max_wt = max(max_wt, tim[i].first - r);
            l = tim[i].first, r = tim[i].second;
        }
        max_t = max(max_t, r - l);
    }
    cout << max_t << ' ' << max_wt << endl;
    return 0;
}